<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="获返佣会员名称" prop="uname">
        <el-input
          v-model="queryParams.uname"
          placeholder="请输入获返佣会员名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="返佣会员名称" prop="fname">
        <el-input
          v-model="queryParams.fname"
          placeholder="请输入返佣返佣会员名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单号" prop="oid">
        <el-input
          v-model="queryParams.oid"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="日期">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['video:DCommissionRecord:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['video:DCommissionRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="DCommissionRecordList" >
      <el-table-column label="获返佣会员名称" align="center" prop="uname" />
      <el-table-column label="返佣会员名称" align="center" prop="fname" />
      <el-table-column label="订单号" align="center" prop="oid" />
      <el-table-column label="订单金额" align="center" prop="orderAmount" />
      <el-table-column label="佣金比例" align="center" prop="commissionRate" />
      <el-table-column label="返佣金额" align="center" prop="commissionAmount" />
      <el-table-column label="返佣时间" align="center" prop="createTime" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['video:DCommissionRecord:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['video:DCommissionRecord:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改返佣记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="被返佣会员id" prop="uid">
          <el-input v-model="form.uid" placeholder="请输入被返佣会员id" />
        </el-form-item>
        <el-form-item label="返佣的会员id" prop="coid">
          <el-input v-model="form.coid" placeholder="请输入返佣的会员id" />
        </el-form-item>
        <el-form-item label="订单id" prop="oid">
          <el-input v-model="form.oid" placeholder="请输入订单id" />
        </el-form-item>
        <el-form-item label="订单金额" prop="orderAmount">
          <el-input v-model="form.orderAmount" placeholder="请输入订单金额" />
        </el-form-item>
        <el-form-item label="佣金比例" prop="commissionRate">
          <el-input v-model="form.commissionRate" placeholder="请输入佣金比例" />
        </el-form-item>
        <el-form-item label="返佣金额" prop="commissionAmount">
          <el-input v-model="form.commissionAmount" placeholder="请输入返佣金额" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDCommissionRecord, getDCommissionRecord, delDCommissionRecord, addDCommissionRecord, updateDCommissionRecord } from "@/api/video/DCommissionRecord";

export default {
  name: "DCommissionRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 返佣记录表格数据
      DCommissionRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        uname: null,
        fname: null,
        oid: null,
        beginTime: null,
        endTime: null

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 日期范围
      dateRange: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询返佣记录列表 */
    getList() {
      this.loading = true;
      if(this.dateRange.length>0){
        this.queryParams.beginTime=this.dateRange[0];
        this.queryParams.endTime=this.dateRange[1];
      }else{
        this.queryParams.beginTime=null;
        this.queryParams.endTime=null;
      }
      listDCommissionRecord(this.queryParams).then(response => {
        this.DCommissionRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uname: null,
        fname: null,
        oid: null,
        beginTime: null,
        endTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange= [];
      this.queryParams.beginTime=null;
      this.queryParams.endTime=null;
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加返佣记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDCommissionRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改返佣记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDCommissionRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDCommissionRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除返佣记录编号为"' + ids + '"的数据项？').then(function() {
        return delDCommissionRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('video/DCommissionRecord/export', {
        ...this.queryParams
      }, `DCommissionRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
